class ObjectAnimator {
    constructor(viewId) {
        this.viewId = viewId;
        this.funIdMap = {
            onStart: 'start1',
            onEnd: 'end1'
        };
        registry.register(this, this.funIdMap);
    }
}

const registry = new FinalizationRegistry((object) => {
    // console.log(`${object.onStart} 于 ${new Date().getTime()} 被垃圾回收干掉了`);
    // console.log(`${object.onEnd} 于 ${new Date().getTime()} 被垃圾回收干掉了`);
    removeUnusedCallback(object);
});

function removeUnusedCallback(funIdMap) {
    // console.log('removeUnusedCallback', funIdMap);
    Object.keys(funIdMap).forEach((key) => {
        console.log(`execute ${funIdMap[key]}`)
    })
}

let obj1 = new ObjectAnimator(100);
let obj2 = new ObjectAnimator(100);
obj2.funIdMap.onStart = 'start2';
obj2.funIdMap.onEnd = 'end2';

obj1 = null;
obj2 = null;

gc();
